<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="${webPath }/lib/css/global.css" media="all" />
<link rel="stylesheet" href="${webPath }/lib/layuicms/layui/css/layui.css" media="all" />
 <%@include file="/WEB-INF/common/script.jsp"%><!--静态包含-->
 <script type="text/javascript">
 var classflyId = '${modle.id }'.trim();
 var userId = '${user.id}';
 </script>
<title>Insert title here</title>
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>错题集</legend>
 </fieldset>
 <table id="demo" lay-filter="demo"></table>
  <div align="center" id="laypageDiv"></div>
  <script type="text/javascript" src="${webPath }/lib/layuicms/layui/layui.js"></script>
 	<script type="text/html" id="barTool">
  <a class="layui-btn layui-btn-xs updateBtn" lay-event="detail">查看错题</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	</script>
  <script type="text/javascript">
  layui.use(['table','layer', 'laypage','jquery','form','element','laytpl'], function() {
	  var $ = layui.jquery
	  ,table = layui.table
	  ,layer = layui.layer
	  ,form = layui.form
	  ,laytpl = layui.laytpl
	  ,laypage = layui.laypage
	  ,element = layui.element;
	
	  
		table.render({
		    elem: '#demo'
			,url:webPath+'errorErrorSubjectController/ajaxList'
			,page:true
			,where: {userId:userId}
			,height : "full-125"
			,cols: [[{field:'subjectId', title: '错误题号 ', sort:true }
			,{field:'content', title: '错误日志 ', sort:false }
			,{field:'creatDate', title: '创建时间 ', sort:true }
			,{field:'updateDate', title: '修改时间 ', sort:true }
			,{fixed:'right',title:'操作', width:178, align:'center', toolbar: '#barTool'}
			 ]]
			 });
		
		 table.on('tool(demo)', function(obj){
			 switch (obj.event) {
		        case 'detail':
		            //TODO
		            openTopic(obj.data.subjectId);
		            break;
		        case 'del':
		            //TODO
		            del(obj.data.id);
		            break;
		        default :
		            //TODO
		            layer.msg('我们不提供该功能');
		    }
		 });
		 //删除错题信息
		 function del(id){
			 $.ajax({
					url : webPath + 'errorErrorSubjectController/delete',
					data:{id:id},
					type : 'post', 
					dataType : 'json',
					success : function(json) {
						if(json.code === 200){
							layer.msg(json.msg);
						    event.reload('demo');
						}
					},
					error : function() {
						layer.msg('系统出错,请联系管理员');
					}
				});
		 };
		// 方法事件
			var event={
					reload:function(id,data){
						//执行重载
						table.reload(id, {
							page : {
								curr : 1 //重新从第 1 页开始
							},
							where : data //参数
						});
						
					}
			}
		  //查看题目
		    function openTopic(id){
		         var index = layui.layer.open({
		            title : "查看错题",
		            type : 2,
		            content : webPath+"subjectController/saveUpdatePage?id="+id,
		            success : function(layero, index){
		                var body = layui.layer.getChildFrame('body', index);
		                setTimeout(function(){
		                    layui.layer.tips('点击此处返回用户列表', '.layui-layer-setwin .layui-layer-close', {
		                        tips: 3
		                    });
		                },500)
		            }
		        })
		        layui.layer.full(index);
		        window.sessionStorage.setItem("index",index);
		        //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
		        $(window).on("resize",function(){
		            layui.layer.full(window.sessionStorage.getItem("index"));
		        }) 
		    };
  }); 
  </script>
  
</body>
<textarea class="site-demo-text" id="tpldemo"  style="display:none;">
 {{#  layui.each(d, function(index, item){ }}
  <li class="layui-timeline-item">
    <i class="layui-icon layui-timeline-axis">&#xe63f;</i>
    <div class="layui-timeline-content layui-text">
      <h3 class="layui-timeline-title">{{ item.id }}.{{=item.content }}</h3>
      <form class="layui-form"  id="{{item.id }}" >
          <table class="layui-table"  lay-skin="line">
          <!-- 模板解析单选/多选 -->
          {{#  item.fn  = item.reslut == 1?'radio' :'checkbox'; }}
          <tbody>
          <tr>
           {{#  item.name = item.fn === 'radio'? item.id:item.id+'[0]'; }}
          <th><input type="{{ item.fn }}" name="{{item.name}}" value="A" title="A." lay-skin="primary">{{=item.optionA }}</input></th>
          </tr> 
          <tr>
           {{#  item.name = item.fn === 'radio'? item.id:item.id+'[1]';  }}
          <th><input type="{{ item.fn }}" name="{{item.name}}" value="B" title="B."  lay-skin="primary">{{=item.optionB }}</input></th>
          </tr> 
          <tr>
           {{#  item.name = item.fn === 'radio'? item.id:item.id+'[2]';  }}
          <th><input type="{{ item.fn }}" name="{{item.name}}" value="C" title="C."  lay-skin="primary">{{=item.optionC }}</input></th>
          </tr> 
          <tr>
           {{#  item.name = item.fn === 'radio'? item.id:item.id+'[3]';  }}
          <th><input type="{{ item.fn }}" name="{{item.name}}" value="D" title="D." lay-skin="primary">{{=item.optionD }}</input></th>
          </tr> </tbody>
          </table>
          <button id="{{ item.id}}" class="layui-btn layui-btn-normal" lay-submit lay-filter="btn">提交答案</button>
          </form>
    </div>
  </li>
  {{#  }); }}
 </textarea>
</html>